home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_002 / microemacs / keyboard.asm < prev    next >
Assembly Source File  |  1992-05-06  |  3KB  |  103 lines

  1.  
  2.         title   Keyboard Driver
  3.         name    Keyboard
  4.  
  5.         include machine.ah
  6.         include dos.mac
  7.         pseg
  8.  
  9. if DEC_Rainbow
  10. ;+
  11. ; Function:
  12. ;
  13. ;       The Read_Keyboard function returns a unique 16-bit code for esentially
  14. ;       all keys on the keyboard.
  15. ;
  16. ;         15  14  13  12  11  10  9   8   7   6   5   4   3   2   1   0
  17. ;       +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  18. ;       |                   | C | S | F |             code              |
  19. ;       +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  20. ;               F = 1, this is a function key
  21. ;               S = 1, shift key in effect
  22. ;               C = 1, control key in effect
  23. ;
  24. ; Returns:
  25. ;
  26. ;-
  27.  
  28. ROM             equ     18H             ; new ROM access
  29. Function_Key    equ     01H             ; this is a function key
  30. Shift_Flag      equ     02H             ; shift key in effect
  31. Control_Flag    equ     04H             ; control key in effect
  32. Caps_Lock_Flag  equ     08H             ; caps lock key in effect
  33.  
  34.         public  Read_Keyboard
  35.  
  36. $proc Read_Keyboard
  37.         push    ES                      ; Save ES
  38.         mov     DI,6                    ; Level 1 console input
  39.         int     ROM
  40.         cmp     CL,0                    ; Anything?
  41.         je      Read_80                 ; No, return -1
  42.         cmp     CL,1                    ; Any Level 2 characters?
  43.         jne     Read_10                 ; No, go process Level 1 character
  44.  
  45. ; Here to fetch the Level 2 character left in the buffer.
  46.  
  47.         mov     DI,2                    ; Level 2 console input
  48.         int     ROM
  49.         cmp     CL,0                    ; Anything?
  50.         je      Read_80                 ; No
  51.         jmp     Read_90
  52.  
  53. ; Here to process a Level 1 character
  54.  
  55. Read_10:
  56.         and     AH,0F7H                 ; clear caps lock flag
  57.         jmp     Read_90
  58.  
  59. Read_80:
  60.         mov     AX,-1                   ; Return -1 to denote no character
  61.  
  62. Read_90:
  63.         pop     ES                      ; Restore ES
  64.         ret                             ; Return to caller
  65.  
  66. $endp Read_Keyboard
  67.  
  68. endif
  69.  
  70. if IBM_PC or Tandy_2000
  71.  
  72.         public  Read_Keyboard
  73.  
  74. $proc Read_Keyboard
  75.         mov     AH,1
  76.         int     16H                     ; Scan the keyboard
  77.         jz      Read_Keyboard_1         ; No character available
  78.         mov     AH,0                    ; Yes
  79.         int     16H                     ; Read keyboard
  80.         cmp     AL,0                    ; Extended character
  81.         je      Read_Keyboard_2         ; Yes
  82.         mov     AH,0                    ; No, normal character
  83.         ret
  84.  
  85. Read_Keyboard_1:
  86.         mov     AX,-1                   ; Denote "no character available"
  87.         ret
  88.  
  89. Read_Keyboard_2:                        ; Extended character
  90.         mov     AL,AH
  91.         mov     AH,01H                  ; Set the "function key" flags
  92.         ret
  93.  
  94. $endp Read_Keyboard
  95.  
  96. endif
  97.  
  98.         endps
  99.         end
  100. 
  101.  
  102. OK
  103.